import updateManager from './common/updateManager';
// const request = require("utils/request.js");

App({
  onLaunch: function () {
    // 登录获取 token
    // this.verifyToken();
  },
  onShow: function () {
    updateManager();
    setTimeout(() => {
      console.log('%cSpringDoor Welcome...', 'background:#000;color:#FFC800')
    }, 1000);
  },

  globalData: {
    baseUrl: 'https://wxapi.llshs.cn/wxd-api'
    // baseUrl: 'https://127.0.0.1:8089/wxd-api'
  },

  verifyToken() {
    console.log('app.js - verifyToken')
    const token = wx.getStorageSync('token');
    if (!token) {
      wx.login({
        success: (res) => {
          if (res.errMsg == 'login:ok') {
            const jsCode = res.code;
            request("https://wxapi.llshs.cn/wxd-api/login", { "jsCode": jsCode }, "POST")
              .then(res => {
                if (res.code == '500') {
                  console.log('error: ', res.msg);
                } else if (res.code = '200') {
                  if (res.data.openid && res.data.token) {
                    wx.setStorageSync('token', res.data.token);
                  }
                }
              })
          }
        },
      })
    }
  }
});
